<?php
namespace app\api\controller;

use app\api\model\ArticleModel;
use think\Controller;
use think\Request;
use think\Db;

class Article extends Controller
{
    /**
     * 获取信息详情
     */
    public function getOne(Request $request){
        $id = $request->get('id');
        $result = ArticleModel::instance()->getOne($id);
        if ($result) {
            return json_encode(['code'=>1,'msg'=>'success','data'=>$result]);
        }else{
            return json_encode(['code'=>0,'msg'=>'error','data'=>'']);
        }
    }
    /**
     * 获取信息列表
     */
    public function getList(Request $request){
        $data   = $request->get();
        $return = ArticleModel::instance()->getList($data);
        $list   = $return[0];
        if ($list) {
            return json_encode(['code'=>1,'msg'=>'success','data'=>$list,'page'=>$return[1],'count'=>$return[2]]);
        }else{
            return json_encode(['code'=>0,'msg'=>'error','data'=>'']);
        }
    }
    /*
    * 获取分类
    */
    public function getCat(){
        $return = ArticleModel::instance()->getCat();
        if ($return) {
            return json_encode(['code'=>1,'msg'=>'success','data'=>$return]);
        }else{
            return json_encode(['code'=>0,'msg'=>'error','data'=>'']);
        }
    }

}
